package com.cqupt.controller;

import com.cqupt.dao.PictureMapper;
import com.cqupt.paging.Paging;
import com.cqupt.pojo.Goods;
import com.cqupt.pojo.User;
import com.cqupt.service.GoodsService;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/*
功能：查询商品，下架商品，上架商品，添加商品，编辑商品，满意度提交，投诉表提交，查询分页商品表,调取图片路径,投诉表分页首页
 */

@Controller
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    //添加商品
    @RequestMapping("/goods/goodsAdd")
    @ResponseBody
    public int insertGoods(Goods goods) {
        //goods.setName("30元话费充值卡");
        //goods.setScore(30);
        //goods.setDescription("好耶");
        //goods.setNumber(99);

        String[] list = goods.getPicpath().split("\\\\");
        String path = "http://localhost:8080/boss_system/picture/" + list[1];
        goods.setPicpath(path);
        //默认为上架商品
        goods.setState(1);
        return goodsService.insertGoods(goods);
    }

    //查询商品列表
    @RequestMapping("/goods/select")
    @ResponseBody
    public  List select() {
        List list = goodsService.selectGoods();
        return list;
    }

    //查询分页商品表
    @RequestMapping("/goods/selectLimit")
    @ResponseBody
    public  List selectPageGoods(Integer number) {
        //number = 2;
      return  goodsService.selectPageGoods(number);
    }

    //调取图片
    @RequestMapping("/goods/picturePath")
    @ResponseBody
    public List getPicturePath(String page){
       page = "life";
        return goodsService.getPicturePath(page);
    }

    //下架商品
    @RequestMapping("/goods/offlineGoods")
    @ResponseBody
    public int offlineGoods(Integer id) {
        //id = 2;
        return goodsService.offlineGoods(id);

    }
    //上架商品
    @RequestMapping("/goods/onlineGoods")
    @ResponseBody
    public int onlineGoods(Integer id) {
        //id = 2;
        return goodsService.onlineGoods(id);

    }
    //更新商品

    @RequestMapping("/goods/updateGoods")
    @ResponseBody
    public int updateGoods(Goods goods )  {
        //goods.setId(11);
        //goods.setName("黑人牙膏2");
        //goods.setScore(3);
        //goods.setState(0);
        //goods.setNumber(20);
        //goods.setDescription("修改成功");
        return goodsService.updateGoods(goods);
    }

    //删除商品
    @RequestMapping("/goods/deleteGoods")
    @ResponseBody
    public int deleteGoods(Integer id)  {
        //id = 3;
     return  goodsService.deleteGoods(id);
    }

    @RequestMapping("/goods/feedBack")
    @ResponseBody
    //用户体验反馈
    public int feedBack(User user, Integer description) {
        //user.setUsername("user1");
        //description = 5;
        return goodsService.feedBack(user, description);
    }

    @RequestMapping("/goods/complaint")
    @ResponseBody
    //用户投诉
    public  int complaint(User user,String content) {
        //user.setId(3);
        //content = "商品与图片不符";

        return goodsService.complaint(user,content);
    }

//    @RequestMapping("/goods/getComplaint")
//    @ResponseBody
//    //投诉表查询
//    public  List complaintListHomePage() {
//        return goodsService.complaintListHomePage();
//    }
//
//    @RequestMapping("/goods/getComplaintLimit")
//    @ResponseBody
//    //投诉表查询分页
//    public Paging complaintListPage(Integer number) {
//        number =3;
//        return goodsService.complaintListPage(number);
//    }

}